package com.yunshang.shoppingmall.config;


import com.yunshang.shoppingmall.entity.PrivilegeURL;
import com.yunshang.shoppingmall.service.PrivilegeURLService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class AdminIntercepter implements WebMvcConfigurer {

    @Autowired
    PrivilegeURLService privilegeURLService;
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> url=new ArrayList<>();
        List<PrivilegeURL> privilegeURLList =privilegeURLService.selectPriURLList();
        for (int i = 0; i <privilegeURLList.size() ; i++) {
           url.add(privilegeURLList.get(i).getResourceUrl());
        }

        registry.addInterceptor(new LoginInterceptor() ).addPathPatterns(url);

    }



}
